#-*- coding:utf-8 -*-
'''
Created on Dec 8, 2012

@author: bbg
'''
import unittest
from webob import Response, Request
from service.public.cdkey_service import CdkeyService
from service.server_config import SrvConfig
from logic.cdkey_mgr import CdkeyManager
import uuid

class Test(unittest.TestCase):
    

    def setUp(self):
        self.testCompanyId = 20001
        self.testShopId = 1
        self.testUserName = 'linshili'
        self.testPwd = '888'
        self.testUUID = 'adde87ae-1821-4d82-b748-d014d41ccf38'
        dbsession = SrvConfig.getDefaultDBSession()
        #self.testCdkey = CdkeyManager.generateCdkeysForCompany(20001, 1, dbsession)
        self.testCdkey = '4DA4K-VBBMN-PPIA8-9LSCO'
        dbsession.close()



    def tearDown(self):
        pass


    def testActive(self):
        #激活cdkey
        params = {
                  'cdkey': self.testCdkey,
                  'uuid': self.testUUID,
                  'username': self.testUserName,
                  'type': 0,
                  'pwd': self.testPwd,
                  'company_id': self.testCompanyId,
                  'shop_id': self.testShopId
                  }
        req = Request.blank(path = '/poscloud/v1/cdkey', POST = params)
        res = Response()
        CdkeyService.process(req, res)
        print res.text
        
    
    def testAuthenticate(self):
        #验证cdkey        
        params = {
                  'cdkey': self.testCdkey,
                  'uuid': self.testUUID,
                  'username': self.testUserName,
                  'type': 1,
                  'token': '',
                  'userid': 3,
                  'right_name': 'edit_cdkey'                                  
                  }
        req = Request.blank(path = '/poscloud/v1/cdkey', POST = params)
        res = Response()
        CdkeyService.process(req, res)
        


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testActive']
    unittest.main()